﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Business.Manager;
using Business.IManager;
using Entity;

namespace OnlinePayment.Admin
{
    public partial class OperatorUpdate : System.Web.UI.Page
    {
        IDepartmentManager departmentManage = new DepartmentManager();
        IAccountManager accountManager = new AccountManager();
        int operatorId = 2;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                bindDept();
                bindRole();
                operatorId = 2; //Convert.ToInt32(Session["operatorId"]);//要改
                bindOperator();
                //权限检查
               
            }

        }

        private void bindOperator()
        {
           Operator oper=accountManager.selectOperatorInfor(operatorId);
           txtOperName.Text = oper.OperatorName;
           depList.SelectedItem.Value = Convert.ToString(oper.DeptId);
           roleList.SelectedItem.Value = Convert.ToString(oper.RoleId);
        }

        private void bindRole()
        {
            roleList.DataSource = accountManager.getAuthorityDS();
            roleList.DataTextField = "roleName";
            roleList.DataValueField = "roleId";
            roleList.DataBind();
        }

        private void bindDept()
        {
            depList.DataSource = departmentManage.getDepartment();
            depList.DataTextField = "depName";
            depList.DataValueField = "deptId";
            depList.DataBind();
        }

        protected void btn_update_Click(object sender, EventArgs e)
        {
            Operator oper = new Operator();
            oper.OperatorName=txtOperName.Text ;
            oper.DeptId=Convert.ToInt32(depList.SelectedItem.Value);
            oper.RoleId = Convert.ToInt32(roleList.SelectedItem.Value);
            if (accountManager.updataOperator(operatorId,oper))
            {
                Response.Write(" <script language=javascript> alert( '修改成功 '); </script>");
            }
            else
            {
                Response.Write(" <script language=javascript> alert( '修改失败 '); </script>");
            }
        }
    }
}